package com.winona.code;

import java.util.HashMap;
import java.util.Map;

public class ResourceManager {
	private static ResourceManager instance;
	private Map<String, Resource> resources = new HashMap<String, Resource>();

	public static ResourceManager getInstance() {
		if (instance != null)
			return instance;
		synchronized (ResourceManager.class) {
			if (instance == null) {
				instance = new ResourceManager();
			}
		}
		return instance;
	}

	public void addResource(Resource resource) {
		this.resources.put(resource.getClass().getName(), resource);
	}

	public void removeResource(Resource resource) {
		this.resources.remove(resource);
	}

	public void clear() {
		for (Resource resource : resources.values()) {
			resource.clear();
		}
	}
	
	public void releaseAll() {
		for (Resource resource : resources.values()) {
			resource.releaseResource();
		}
	}
	
}
